﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{
    /*
     * 
     * 
     * The decimal number, 585 = 1001001001 (binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)

     * 
     * */
    class Problem36
    {
        public static string Calculate()
        {
            //nemogu parni brojevi, jer bi u base2 imali nulu na kraju. *10 je parni broj :)

            var resutl = CommonFunctions.GetPalindromes();
            int sum = 0;

            //int count = 0;

            //foreach (int i in resutl)
            //{
            //    if (i > 8000000)
            //        break;



            //    if (i < 1000 && i > 100)
            //        count++;

            //    Console.WriteLine(i);
            //}

            //Console.WriteLine("Total: {0}", count);

            foreach (int i in resutl)
            {

                if (i > 100000000)
                    break;

                if (i < 1000000)
                {
                    string binary = CommonFunctions.GetBinaryRepresentation(i);

                    if (CommonFunctions.IsPalindrome(binary))
                    {
                        sum += i;
                        Console.WriteLine("{0} - {1}", i, binary);
                    }
                }
            }


            return sum.ToString();
        }
    }
}
